package com.cn.kehong.controller;


import com.cn.kehong.api.IPlanYearService;
import com.cn.kehong.domain.PlanYear;
import com.cn.kehong.utils.CommonUtil;
import com.cn.kehong.utils.JsonResponse;
import com.cn.kehong.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/planYear")
public class PlanYearController {

    @Autowired
    private IPlanYearService planYearService;

    @RequestMapping("/getPlanYearList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<PlanYear>> getPlanYearList(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<PlanYear>> response = new JsonResponse<List<PlanYear>>();
        List<PlanYear> list  = planYearService.getPlanYearList(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return  response;
    }

    @RequestMapping("/getSelectPlanYears/{frontToken}")
    @ResponseBody
    public JsonResponse<List<String>> getSelectPlanYears(@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<String>> response = new JsonResponse<List<String>>();
        List<String> list  = planYearService.getSelectPlanYears();
        response.setResult(list);
        response.setSuccess(true);
        return  response;
    }

    @ResponseBody
    @RequestMapping("/addPlanYear/{frontToken}")
    public JsonResponse<String> addPlanYear(@RequestBody PlanYear planYear, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = planYearService.addPlanYear(planYear);
        return CommonUtil.getResponseData(response,result);
    }


    @ResponseBody
    @RequestMapping("/updatePlanYear/{frontToken}")
    public JsonResponse<String> updatePlanYear(@RequestBody PlanYear planYear, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = planYearService.updatePlanYear(planYear);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/updateCheckPlanYear/{frontToken}")
    public JsonResponse<String> updateCheckPlanYear(PlanYear planYear, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = planYearService.updateCheckPlanYear(planYear);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/updatePlanYearVersion/{frontToken}")
    public JsonResponse<String> updatePlanYearVersion(@RequestBody PlanYear planYear, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = planYearService.updatePlanYearVersion(planYear);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/deletePlanYearById/{frontToken}")
    public JsonResponse<String> deletePlanYearById(String id, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = planYearService.deletePlanYearById(id);
        return CommonUtil.getResponseData(response,result);
    }


    @RequestMapping("/getCheckPlanYearCount/{frontToken}")
    @ResponseBody
    public JsonResponse<Integer> getCheckPlanYearCount(@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<Integer> response = new JsonResponse<Integer>();
        Integer count  = planYearService.getCheckPlanYearCount();
        response.setResult(count);
        response.setSuccess(true);
        return  response;
    }
}
